package com.ilove.frame;

import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixConstants;
import org.kalmeo.kuix.widget.Screen;
import org.kalmeo.kuix.widget.Widget;
import org.kalmeo.util.frame.Frame;
import com.ilove.core.*;
import com.ilove.media.frame.CategoryFrame;
import com.ilove.model.*;
public class MainFrame implements Frame {

	public static MainFrame instance = new MainFrame();
	// MainFrame's Screen
	private Screen screen;
	private final Pad pad = new Pad();
	public void showScreen() {
		if (screen != null) {
			screen.setCurrent();
		}
	}
	public void onAdded() {
		try {
			ILOVE.isActive = pad.isActived();
			if(!ILOVE.isActive) {
			//if(true){
				Widget splash = Kuix.loadWidget("/xml/splash.xml", null);
				Kuix.splash(2000, splash, "showMainScreen");
			// Load the screen
			screen = Kuix.loadScreen(ILOVEContants.MAINFRAME_SCREEN, pad);
			screen.setCurrent();
			}
		} catch (Exception e) {
			Kuix.alert(e);
			e.printStackTrace();
		}
	}

	public boolean onMessage(Object identifier, Object[] arguments) {
		if ("showMainScreen".equals(identifier)) {
			showScreen();
			return false;
		} else if ("askQuit".equals(identifier)) {
			Kuix.alert(Kuix.getMessage("ASK_QUIT"),
					KuixConstants.ALERT_QUESTION | KuixConstants.ALERT_YES
							| KuixConstants.ALERT_NO, "!exit", null);
			return false;
		} 
		else if ("ringtone".equals(identifier)) {
			com.ilove.music.frame.CategoryFrame.instance.id = 1;
			com.ilove.music.frame.CategoryFrame.instance.name = "RINGTONE";
			com.ilove.music.frame.CategoryFrame.instance.code = "NHAC_CHUONG";
			Kuix.getFrameHandler().pushFrame(com.ilove.music.frame.CategoryFrame.instance);
		}
		else if ("ringback".equals(identifier)) {
			com.ilove.music.frame.CategoryFrame.instance.id = 1;
			com.ilove.music.frame.CategoryFrame.instance.name = "Nhac cho";
			com.ilove.music.frame.CategoryFrame.instance.code = "RING_BACK";
			Kuix.getFrameHandler().pushFrame(com.ilove.music.frame.CategoryFrame.instance);
		}
		else if ("game".equals(identifier)) {
			CategoryFrame.instance.id = 2;
			CategoryFrame.instance.name = "GAME";
			CategoryFrame.instance.code = "GAME";
			Kuix.getFrameHandler().pushFrame(CategoryFrame.instance);
		}
		else if ("MEOVAT".equals(identifier)) {
			com.vnt.IndexFrame.instance.id = 0;
			com.vnt.IndexFrame.instance.name = "MEO VAT";
			com.vnt.IndexFrame.instance.code = "1089";
			Kuix.getFrameHandler().pushFrame(com.vnt.IndexFrame.instance);
		}
		else if ("stories".equals(identifier)) {
			com.vnt.IndexFrame.instance.id = 0;
			com.vnt.IndexFrame.instance.name = "Truyen";
			com.vnt.IndexFrame.instance.code = "1088";
			Kuix.getFrameHandler().pushFrame(com.vnt.IndexFrame.instance);
		}
		else if ("wallpaper".equals(identifier)) {
			CategoryFrame.instance.id = 3;
			CategoryFrame.instance.name = "Hinh nen";
			CategoryFrame.instance.code = "HINH_NEN";
			Kuix.getFrameHandler().pushFrame(CategoryFrame.instance);
		}
		else if ("UNG_DUNG".equals(identifier)) {
			CategoryFrame.instance.id = 2;
			CategoryFrame.instance.name = "Ứng dụng";
			CategoryFrame.instance.code = "UNG_DUNG";
			Kuix.getFrameHandler().pushFrame(CategoryFrame.instance);
		}
		else if ("VIDEO".equals(identifier)) {
			com.ilove.video.frame.CategoryFrame.instance.id = 1;
			com.ilove.video.frame.CategoryFrame.instance.name = "Video Clip";
			com.ilove.video.frame.CategoryFrame.instance.code = "VIDEO_CLIP";
			Kuix.getFrameHandler().pushFrame(com.ilove.video.frame.CategoryFrame.instance);
		}
		else if("weather".equals(identifier)) {
			Kuix.getFrameHandler().pushFrame(com.ilove.weather.frame.MainFrame.instance);
			return false;
		}
		else if("friend".equals(identifier)) {
			Kuix.getFrameHandler().pushFrame(com.ilove.friend.frame.FriendMainFrame.instance);
			return false;
		}
		else if ("lottery".equals(identifier)) {
			Kuix.getFrameHandler().pushFrame(com.ilove.lottery.frame.LotteryMainFrame.instance);
			return false;
		}
		else if ("schedules".equals(identifier)) {
			com.vnt.IndexFrame.instance.id = 5;
			com.vnt.IndexFrame.instance.name = "";
			com.vnt.IndexFrame.instance.code = "";
			Kuix.getFrameHandler().pushFrame(com.vnt.IndexFrame.instance);
		}
		else if ("about".equals(identifier)) {
			Kuix.getFrameHandler().pushFrame(AboutFrame.instance);
			return false;
		}
		else if ("sendsms".equals(identifier)) {
			System.out.println(ILOVE.KeyActive);
			new SMSender(ILOVE.KeyActive,"7085").send();
			return false;
		}
		return true;
	}
	public void onRemoved() {
	}
}
